if ($(window).width() <= 768) {
    $('.img-box').css({"height": `${$('.img-box').width()}px`});
}
$('.img-box').click((dom) => {
    let pswpElement = document.querySelectorAll('.pswp')[0];
    let targetSrc = dom.target.getAttribute('src');
    let targetIndex;
    let galleryId = dom.target.getAttribute('data-gallery-id');
    let imageList = $(`img[data-gallery-id=${galleryId}]`);
    let itemList = [];
    for (let i = 0; i < imageList.length; i++) {
        let itemSrc = imageList[i].getAttribute('src');
        let itemsize = imageList[i].getAttribute('data-size').split('x');
        if (targetSrc === itemSrc) {
            targetIndex = i;
        }
        itemList.push({
            src: itemSrc,
            w: parseInt(itemsize[0], 10),
            h: parseInt(itemsize[1], 10)
        })
    }
    // console.log(targetIndex);
    // console.log(itemList);
    let options = {
        // 索引:当前点击
        index: targetIndex,
        // 淡入淡出
        showHideOpacity: true,
        // 图片循环
        loop: false,
        history: false,
        shareButtons: [
            {id: 'download', label: '保存图片', url: '{{raw_image_url}}', download: true}
        ], // 分享按钮
    }
    let gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, itemList, options);
    gallery.init();
})